import {api} from './libs/api.js';
let _self;
const img = '/static/logo.png';
export const index =  {
	data() {
		return {
			latitude: 23.099994,//当前纬度
			longitude: 113.324520,//当前精度
			
			covers: [
				{
					id:1,
					latitude: 23.099994,
					longitude: 113.324520,
					width:14,
					height:20,
					customCallout:{
						display:"ALWAYS",
						anchorX:0,
						anchorY:0,
					}
					//iconPath: '../../static/logo.png'
				},{
					id:2,
					latitude: 23.099994,
					longitude: 113.322520,
					width:14,
					height:20,
					customCallout:{
						display:"ALWAYS",
						anchorX:0,
						anchorY:0,
					}
				},
			]
		}
	},
	
	mounted() {
		_self = this;
	},
	onReachBottom:function(e){
		/*this.params.page+=1;
		this.initData();*/
	},
	onLoad:function(option) {
		uni.getLocation({
			type: 'wgs84',
			success: function (res) {
				_self.longitude=res.longitude;
				_self.latitude=res.latitude;
				/*console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);*/
			}
		});
		//this.tabSubItem=option.status;
	},
	
	onReady() {
		this._mapContext = uni.createMapContext("map", this);
		// 仅调用初始化，才会触发 on.("markerClusterCreate", (e) => {})
		this._mapContext.initMarkerCluster({
			enableDefaultStyle: false,
			zoomOnClick: true,
			gridSize: 60,
			complete(res) {
			  console.log('initMarkerCluster', res)
			}
	  });
	
	  this._mapContext.on("markerClusterCreate", (e) => {
		console.log("markerClusterCreate", e);
	  });
	
	  //this.addMarkers();
	},
	
	methods: {
		async initData(){
			
		},
		addMarkers() {
		  const marker = {
		    id: 1,
		    iconPath: img,
		    width: 50,
		    height: 50,
		    joinCluster: true, // 指定了该参数才会参与聚合
		    label: {
		      width: 50,
		      height: 30,
		      borderWidth: 1,
		      borderRadius: 10,
		      bgColor: '#ffffff'
		    }
		  };
		
		  const positions = [{
		    latitude: 23.099994,
		    longitude: 113.324520,
		  }, {
		    latitude: 23.099994,
		    longitude: 113.322520,
		  }, {
		    latitude: 23.099994,
		    longitude: 113.326520,
		  }, {
		    latitude: 23.096994,
		    longitude: 113.329520,
		  }]
		
		  const markers = []
		
		  positions.forEach((p, i) => {
		    const newMarker = Object.assign(marker, p)
		    newMarker.id = i + 1
		    newMarker.label.content = `label ${i + 1}`
		    markers.push(newMarker)
		
		    this._mapContext.addMarkers({
		      markers,
		      clear: false,
		      complete(res) {
		        console.log('addMarkers', res)
		      }
		    })
		  })
		  
		  
		}
		
				
	}
}


